<?php
$categories = $this->categories;
$count=count($categories);
if ($count%2!=0){
    $maxlimit=((int)$count/2)+1;

}
else {$maxlimit=((int)$count/2);}
$first_col_categories=array_slice($categories,0,$maxlimit);
$second_col_categories=array_slice($categories,$maxlimit);
?>
<script>
   function  gotoad()
  {
   location.href="/ad/list";
  }
</script>
<input type="button" class="btn" value="Добавить объявление" onClick="gotoad()">

<table class="obyavku">
        <tr>
      <td>
                <?php foreach ($first_col_categories as $category): ?>
                    <div>
                        <span style="font-weight: bold"><?php echo $category['name'] ?></span>
                        <p><?php foreach ($category['children'] as $child): ?>
                        <a href="/ad/view/id/<?php echo $child['id'] ?>"><?php echo $child['name'] ?></a>
                        <?php endforeach; ?></p>
                    </div>
                <?php endforeach; ?>
      </td>
      <td>
                  <?php foreach ($second_col_categories as $category): ?>
                           <div>
                               <span style="font-weight: bold"><?php echo $category['name'] ?></span>
                               <p><?php foreach ($category['children'] as $child): ?>
                               <a href="/ad/view/id/<?php echo $child['id'] ?>"><?php echo $child['name'] ?></a>
                               <?php endforeach; ?></p>
                           </div>
                 <?php endforeach; ?>
      </td>
    </tr>
</table>
